package ruifeng.zcj.communcationring.view;

import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Administrator on 2016/9/14 0014.
 */
public class MySwipeRefreshLayout extends SwipeRefreshLayout {
    // 子View
    ViewGroup viewGroup;

    public MySwipeRefreshLayout(Context context) {
        super(context);
    }

    public MySwipeRefreshLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onTouchEvent(MotionEvent arg0) {

        this.setEnabled(false);

       /* switch (arg0.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if (this.getScrollY() <= 0)
                    this.scrollTo(0, 1);
                break;
            case MotionEvent.ACTION_UP:
                break;
        }*/


        return super.onTouchEvent(arg0);
       /* if (this.getScrollY() > 1){
            this.setEnabled(false);
            return super.onTouchEvent(arg0);
        }else {

        }*/


        // TODO Auto-generated method stub
       /* if (viewGroup != null && viewGroup.getScrollY() > 1) {
            this.setEnabled(false);
            return super.onTouchEvent(arg0);
        } else {
            this.setEnabled(false);
            // 让SwipeRefreshLayout处理本次事件
            return super.onTouchEvent(arg0);
        }*/

    }

    public ViewGroup getViewGroup() {
        return viewGroup;
    }

    public void setViewGroup(ViewGroup viewGroup) {
        this.viewGroup = viewGroup;
        this.viewGroup.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                if (MySwipeRefreshLayout.this.viewGroup.getScrollY() <= 1) {
                    MySwipeRefreshLayout.this.setEnabled(true);
                }
                return false;
            }
        });
    }
}
